import { Controller, Get, Post, Inject, Query, Body } from '@midwayjs/core';
import { PhotoService } from '../service/photo.service';
import { Context } from '@midwayjs/koa';
import { Photo } from '../entity/photo.entity';

@Controller('/photo')
export class PhotoController {
  @Inject()
  photoService: PhotoService;

  @Inject()
  ctx: Context;

  @Get('/queryInfo')
  async findPhotos() {
    const result = await this.photoService.findPhotos();
    return { status: 0, message: 'OK', data: result };
  }

  @Get('/queryById')
  async findPhotoById(@Query('id') id: number) {
    const result = await this.photoService.findPhotoById(id);
    return { status: 0, message: 'OK', data: result };
  }

  @Post('/insert')
  async insertPhoto(@Body() photo: Photo) {
    const result = await this.photoService.savePhoto(photo);
    return { status: 0, message: 'OK', data: result };
  }

  @Post('/update')
  async updatePhoto(@Body() photo: Photo) {
    const result = await this.photoService.updatePhoto(photo);
    return { status: 0, message: 'OK', data: result };
  }

  @Get('/deleteById')
  async deletePhotoById(@Query('id') id: number) {
    const result = await this.photoService.deletePhotoById(id);
    return { status: 0, message: 'OK', data: result };
  }
}
